<?php
/**
 * Created by PhpStorm.
 * User: hhcyc
 * Date: 2018/9/8
 * Time: 17:11
 */

namespace App\Views;


use Xiaoler\Blade\Compilers\BladeCompiler;
use Xiaoler\Blade\Engines\CompilerEngine;
use Xiaoler\Blade\Engines\EngineResolver;
use Xiaoler\Blade\Factory;
use Xiaoler\Blade\Filesystem;
use Xiaoler\Blade\FileViewFinder;

class View
{
    protected static $blade_path;
    protected static $cache_path;

    public static function config($blade_path = '\app\Views', $cache_path = '\storage\framework\cache'){

        $root = realpath(__DIR__.'/../../');



        self::$blade_path = $root.$blade_path;
        self::$cache_path = $root.$cache_path;

        $file     = new Filesystem;
        $compiler = new BladeCompiler($file, self::$cache_path);
        $resolver = new EngineResolver;

        $resolver->register('blade', function () use ($compiler) {
            return new CompilerEngine($compiler);
        });


        $factory = new Factory($resolver, new FileViewFinder($file, [self::$blade_path]));

        return $factory;
    }
}